package com.sjms._04_创建_原型模式;

import java.util.ArrayList;

/**
 * 深拷贝 clone 方式实现
 */
public class Yang_深_clone implements Cloneable {
    public String name;
    public int age;
    public ArrayList<String> list;

    public Yang_深_clone(String name, int age) {
        this.name = name;
        this.age = age;
        this.list = new ArrayList<>();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Yang_深_clone clone = (Yang_深_clone) super.clone();
        clone.list = (ArrayList<String>) list.clone();
        return clone;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void add() {
        this.list.add(" MMM ");
    }


}
